#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>

#include <QGridLayout>
#include <QGroupBox>
#include <QSerialPortInfo>
#include <QSerialPort>
#include <QFile>
#include <QComboBox>
#include <QLabel>
#include <QPushButton>
#include <QtDebug>
#include <QTextEdit>
#include <QProgressBar>
#include <QMessageBox>
#include <QTimer>
#include <QLineEdit>
#include <QFileDialog>
#include <QTextStream>
#include <QByteArray>
#include <QIODevice>

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

private:

    long int vReadFileSize;

    long int vReadFileNum;

    long int vReadFileIndex;

    uint8_t vBuff[2*1024];

    long int vHead;

    long int vCount;

    char vUpdateFlag;

    char vUpdateState;

    QTimer *tim;

    QTimer *vQtimer_FwUpdate;

    QTimer *vQtimer_IspStart;

    QTimer *vQtimer_UpdateMcu;




    QWidget *QWidget_Main;
    QVBoxLayout * VQBoxLayout_Main;         //主布局

    QHBoxLayout *QHBoxLayout_Serial;        //串口布局

    QWidget *vQWidget_FwUpdate_Main;        //IAP升级布局


     //serial
    //布局
    QGroupBox *vQGroupBox_Serial;
    QWidget *vQWidget_Serial_Text;      //文本框显示

    QSerialPort *serial;
    QComboBox *ComBox_Port;
    QComboBox *ComBox_Baud;
    QComboBox *ComBox_DateBit;
    QComboBox *ComBox_StopBit;
    QComboBox *ComBox_CheckBit;

    QPushButton *PushButton_Open;
    QLabel *Label_StateName;
    QLabel *Label_StateDate;
    QLabel *Label_ModeName;
    QLabel *Label_ModeDate;

    QPushButton *PushButton_DebugData;
    QPushButton *PusheBotton_SaveData;

//文本显示
    QTextEdit *vqtextEdit_serialText;
    QVBoxLayout *vqboxLayout_serialText;

//IAP升级控件
   QVBoxLayout *qvboxLayout_FwUpdate_Main;
   QVBoxLayout *qvboxLayout_FwUpdate;

   QWidget *qwidget_FwUpdate_Main;
   QGroupBox *qgroupBox_FwUpdate;

   QWidget *qwidget_FwUpdate_1;
   QHBoxLayout *qhboxLayout_Fw_Update1;

   QWidget *qwidget_FwUpdate_2;
   QHBoxLayout *qhboxLayout_Fw_Update2;

   QWidget *qwidget_FwUpdate_3;
   QHBoxLayout *qhboxLayout_Fw_Update3;

   QWidget *qwidget_FwUpdate_4;
   QHBoxLayout *qhboxLayout_Fw_Update4;

   QLabel *vqLabel_FwUpdate_Path;
   QLineEdit *vqLineEdit_FwUpdate_Path;
   QPushButton *vqPushButton_FwUpdate_Open;

   QLabel *vqLabel_FwUpdate_Dev;
   QComboBox *vqComboBox_FwUpdate_Dev;

   QLabel *vqLabel_FwUpdate_Type;
   QComboBox *vqComboBox_FwUpdate_Type;

   QPushButton *vqPushButton_FwUpdate_Start;
   QLabel *vqLabel_FwUpdate_Prog;

   QProgressBar *vqProgressBar_FwUpdate_Prog;
   QLabel *vqLable_FwUpdate_StateName;

   QLabel *vqLabel_FwUpdate_State_Data;
   QLabel *vqLabel_FwUpdate_Test;






void Serial_init(void);
void revice_data(void);
void FirmWare_Update(void);

void copy_to_buff(uint8_t *buff,uint32_t len);
void Process(void);
uint32_t Analyse_UI(uint8_t *buff,uint32_t len);
uint32_t Analyse_MCU(uint8_t *buff,uint32_t len);

void parse(uint8_t *buff,uint32_t len);
void ComsendDate(uint8_t cmd,uint8_t *buff,uint32_t len);
void Update_UI_Send(uint32_t index, uint8_t *buff, uint32_t len);
void Updat_UI_Start(uint32_t filesize);

void Update_MCU_Iap_Start(uint32_t filesize);
void Update_MUC_Isp_start(uint32_t filesize);

void FirmWareSend(uint32_t index);
void FirmWareSendMcu(uint32_t index);





    Ui::MainWindow *ui;

private slots:
    void SlotPushButton_Open(void);
    void SlotComboBox_FwUpdate_dev(int index);
    void SlotOpenFile(void);
    void SlotFirmwareStat(void);
    void SoltFwUpdateTimerDone(void);
    void SoltFwUpdateTimerIspStart(void);
    void SloatTimerUpdateMcu(void);


};
#endif // MAINWINDOW_H
